import axios from '&helpers/axios';
import { reject } from 'lodash';
import { message } from 'antd'
import qs from 'qs'

const API = {
  addOrPutFsm:'/device/updateFsm',
  selectUTEquip:'/device/selectEquip',
  addOrPutUt:'/device/updateUt',
}


export const models = {
  name: 'setUTMessagePage',
  model: {
    state: {
      FSMneedDatas:{},
      username: "test",
      utEquipDatas:{},
      isSuccess:false,
      equipInfo:{},
    },
    reducers: {
      setState(state, payLoad) {
        return {
          ...state,
          ...payLoad
        };
      }
    },
    effects: dispatch => {
      return {
        async putDataUT(params) {
          const formData = {
            imageId: '5r0y9ktz',
            ...params
          }
          const { code, data, msg } = await axios.post(API.addOrPutUt,qs.stringify(formData));
          console.log(code);
          code === 0 && await dispatch.setUTMessagePage.setState({ isSuccess:true }) && message.success(msg)
          code !== 0 && message.error(msg)
        },
        async selectUTMessage(params) {
          const { code, data } = await axios.post(API.selectUTEquip,qs.stringify(params));
          console.log(code);
          code === 0 && await dispatch.setUTMessagePage.setState({ utEquipDatas:{...data} })
        },
        async getOneUTEquip(params) {
          const { code, data } = await axios.post(API.selectUTEquip, qs.stringify(params))
          code === 0 && await dispatch.setUTMessagePage.setState({ equipInfo: {...data} })
        }
      }
    }
  }
};
